from django.db import models

# Create your models here.


class Order(models.Model):

    """An order/campaign is the root level of an advertising promotion"""

    name = models.CharField(max_length=200)
    order_id = models.IntegerField()
    advertiser_name = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
    start_date = models.DateTimeField('date started')
    end_date = models.DateTimeField('date finished')

    def __unicode__(self):
        orderInfo = str(self.order_id) + ' ' + self.name
        return orderInfo

    def order_start_date(self):
        return self.start_date

    def order_end_date(self):
        return self.end_date

    def was_published_recently(self):
        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

1
class Lineitem(models.Model):

    """Object of orders, contain specifics for an ad"""
    order = models.ForeignKey(Order)
    campaign_id = models.IntegerField()
    name = models.CharField(max_length=200)
    lineitem_id = models.IntegerField()
    start_date = models.DateTimeField('date started')
    end_date = models.DateTimeField('date finished')

    def __unicode__(self):
        return self.name

    def order_start_date(self):
        return self.start_date

    def order_end_date(self):
        return self.end_date
